// {Object, Object} commit方法对象state所有的state对象
// {*} x 传入的值 只能传一个

import {createUnitId, getObjLength, isType, deleteObjectValue} from 'utils/utils';

export default {
    /**
     * 数据：state.zoom地图聚焦点和缩放值
     * @param {Object} obj {x,y,in}
     */
    setZoomData({commit, state}, obj={}){
        if(!isType(obj, 'object')){
            throw new TypeError('setZoomData should input an object');
        }
        commit('SET_ZOOM_DATA', obj);
    },
    /**
     * 数据：state.overlaysPoint设置本地存储的reference
     * @param {Object} obj 本地存储的数据
     */
    setLocalOverlays({commit, state}, obj={}){
        if(!isType(obj, 'object')){
            throw new TypeError('setLocalOverlays should input an object');
        }
        commit('SET_LOCAL_OVERLAYS', obj);
    },
    /**
     * 数据：state.referencePoint设置本地存储的reference
     * @param {Object} obj 本地存储的数据
     */
    setLocalReference({commit, state}, obj={}){
        if(!isType(obj, 'object')){
            throw new TypeError('setLocalReference should input an object');
        }
        commit('SET_LOCAL_REFERENCE', obj);
    },
    /**
     * 数据：state.overlays已标记的形状对象
     * @param {Object} obj {ids}
     */
    setOverlaysData({commit, state}, obj={}){
        if(!isType(obj, 'object')){
            throw new TypeError('setOverlaysData should input an object');
        }
        commit('SET_OVERLAYS_DATA', obj);
    },
    /**
     * 数据：state.reference参照物形状对象
     * @param {Object} obj {ids}
     */
    setReferenceData({commit, state}, obj={}){
        if(!isType(obj, 'object')){
            throw new TypeError('setReferenceData should input an object');
        }
        commit('SET_REFERENCE_DATA', obj);
    },
    /**
     * 数据：state.overlays移除已标记的形状对象
     * @param {Array} id 形状ID
     */
    removeOverlaysData({commit, state}, id){
        if(!isType(id, 'array')){
            throw new TypeError('removeOverlaysData should input an array');
        }
        let newObj = deleteObjectValue(state.overlays, id);
        commit('REMOVE_OVERLAYS_DATA', newObj);
    },
    /**
     * 数据：state.reference移除参照物形状数据
     * @param {Array} id 形状ID
     */
    removeReferenceData({commit, state}, id){
        if(!isType(id, 'array')){
            throw new TypeError('removeReferenceData should input an array');
        }
        let newObj = deleteObjectValue(state.reference, id);
        commit('REMOVE_REFERENCE_DATA', newObj);
    },
    //初始化地图
    initMapObj({commit, state}, obj={}){
        if(!isType(obj, 'object')){
            throw new TypeError('initMapObj should input an object');
        }
        commit('INIT_MAP_OBJ', obj);
    }
}